<template>
  <div class="singer-detail">
    <music-list
      :songs="songList"
      :title="title"
      :pic="pic"
      :loading="loading"
    ></music-list>
  </div>
</template>

<script>
import { getSingerDetail } from "@/api/index";
import MusicList from "@/components/music-list/music-list.vue";
export default {
  props: {
    selectSingerId: Number,
  },
  components: {
    MusicList,
  },
  data() {
    return {
      songs: [],
      loading: true,
    };
  },
  computed: {
    pic() {
      return this.songs?.artist?.picUrl;
    },
    title() {
      return this.songs?.artist?.name;
    },
    //构造歌曲数据
    songList() {
      let arr =
        (this.songs.hotSongs &&
          this.songs.hotSongs.map((item) => {
            return {
              id: item.id,
              name: item.name,
              pic: item.al.picUrl,
              singer: item.ar[0].name,
              url: `https://music.163.com/song/media/outer/url?id=${item.id}.mp3`,
              duration: item.dt,
            };
          })) ||
        [];
      return arr;
    },
  },
  async created() {
    const singerId = this.$route.params.id;
    const { data: singerDetail } = await getSingerDetail(singerId);
    this.songs = singerDetail;
    this.loading = false;
  },
};
</script>

<style lang="scss" scoped>
.singer-detail {
  position: fixed;
  z-index: 10;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  background: $color-background;
}
</style>
